package com.pmoc.framework.core.listener;

import com.pmoc.framework.core.config.driver.DataClient;
import com.pmoc.framework.core.event.AddEvent;
import com.pmoc.framework.core.model.Entity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AddListener implements ApplicationListener<AddEvent> {

    @Autowired
    private DataClient dataClient;

    @Override
    public void onApplicationEvent(AddEvent addEvent) {
        log.info("enter AddListener source:{}", addEvent.getSource());
        if (addEvent.getSource() == null) {
            return;
        }
        dataClient.migrate((Entity) addEvent.getSource());
    }
}
